package cht;

import robocode.control.events.RoundEndedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IBulletSnapshot;
import robocode.control.testing.RobotTestBed;
import static org.junit.Assert.assertTrue;


/**
 * Tests to see whether bullet power decreased upon missing another robot.
 * @author Terrence Chida
 *
 */
public class TestNarchiPowerDown extends RobotTestBed {

  boolean powerDown = false;
  int start;

  /**
   * Specifies that Crazy and Narchi are being matched up in this test.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,cht.Narchi";
  }

  
  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  
  /**
   * After every turn, check for any bullets with power less than 1.
   * 
   * @param event Information on the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IBulletSnapshot bullets[] = event.getTurnSnapshot().getBullets();
    for (int i = this.start; i < bullets.length; i++) {
      // Crazy doesn't shoot bullets with power less than 1, so any/all of these came from Narchi.
      if (bullets[i].getPower() < 1) {
        this.powerDown = true;
      }
      // set the index to loop through, so we don't make redundant calculations.
      this.start = i;
    }
  } // end onTurnEnded()
  
  
  /**
   * At the end of each round, check that the powerDown flag was set.
   * 
   * @param event Information on the current state of the battle.
   */
  @Override
  public void onRoundEnded(RoundEndedEvent event) {
    assertTrue("Check bullet power.", this.powerDown);
  }

} // end TestNarchiPowerDown
